package com.banciyuan.bcywebview.biz.main.mineinfo;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.base.activity.BaseActivity;
import com.banciyuan.bcywebview.base.helper.ActionbarHelper;
import com.banciyuan.bcywebview.base.helper.data.UserDataHelper;
import com.banciyuan.bcywebview.biz.follow.FollowFragment;
import com.banciyuan.bcywebview.biz.main.mineinfo.mark.MyAcgFragment;
import com.banciyuan.bcywebview.biz.main.mineinfo.mark.MyTagFragment;
import com.banciyuan.bcywebview.biz.main.mineinfo.mark.MyWorkSeriesFragment;
import com.banciyuan.bcywebview.biz.pc.TeamsFragment;
import com.banciyuan.bcywebview.utils.intent.gotoUtil;

import java.util.ArrayList;
import java.util.List;


public class MyMarkActivity extends BaseActivity {
    private TabLayout mTabLayout;
    private ViewPager mViewPager;
    private String[] myMarkStringLists;
    private List<Fragment> mFragmentList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mymark_layout);
        initArgs();
        getFragments();
        initActionbar();
        initUi();
        initData();
    }

    private void getFragments() {
        getMarkAcgFragment();
        getMarkTagFragment();
        getMarkSeriesFragment();
        getMarkTeamFragment();
        getMarkFollowing();
    }

    private void getMarkFollowing() {
        FollowFragment followFragment = new FollowFragment();
        Bundle bundle = new Bundle();
        bundle.putString(gotoUtil.INTENT_VALUE_ONE, UserDataHelper.getInstance(this).getUid());
        bundle.putString(gotoUtil.INTENT_VALUE_TWO, "following");
        followFragment.setArguments(bundle);
        mFragmentList.add(followFragment);
    }

    private void getMarkTeamFragment() {
        Bundle bundle = new Bundle();
        bundle.putString("uid", UserDataHelper.getInstance(this).getUid());
        TeamsFragment teamsFragment = new TeamsFragment();
        teamsFragment.setArguments(bundle);
        mFragmentList.add(teamsFragment);
    }

    private void getMarkSeriesFragment() {
        MyWorkSeriesFragment myWorkSeriesFragment = new MyWorkSeriesFragment();
        mFragmentList.add(myWorkSeriesFragment);
    }

    private void getMarkTagFragment() {
        Bundle bundle = new Bundle();
        bundle.putString("uid", UserDataHelper.getInstance(this).getUid());
        MyTagFragment myTagFragment = new MyTagFragment();
        myTagFragment.setArguments(bundle);
        mFragmentList.add(myTagFragment);
    }

    private void getMarkAcgFragment() {
        Bundle bundle = new Bundle();
        bundle.putString("uid", UserDataHelper.getInstance(this).getUid());
        MyAcgFragment myAcgFragment = new MyAcgFragment();
        myAcgFragment.setArguments(bundle);
        mFragmentList.add(myAcgFragment);
    }

    @Override
    protected void initArgs() {
        myMarkStringLists = getResources().getStringArray(R.array.my_mark_lists);
    }

    @Override
    protected void initActionbar() {
        View mActionBarView = findViewById(R.id.base_action_bar);
        ActionbarHelper actionbarHelper=new ActionbarHelper(this,mActionBarView);
        actionbarHelper.setTitle(getString(R.string.choosefriend));
    }

    @Override
    protected void initUi() {
        mTabLayout = (TabLayout) findViewById(R.id.mymark_tablayout);
        mViewPager = (ViewPager) findViewById(R.id.mymark_viewpager);

        mViewPager.setOffscreenPageLimit(myMarkStringLists.length);
        mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mFragmentList.get(position);
            }

            @Override
            public int getCount() {
                return myMarkStringLists.length;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return myMarkStringLists[position];
            }
        });
        mTabLayout.setupWithViewPager(mViewPager);

    }

    @Override
    protected void initData() {

    }
}
